package com.bocai.eelly.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.eelly.R;
import com.bocai.eelly.bean.HistoryListBean;
import com.bocai.eelly.utils.TimeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/30.
 */
public class HistoryCaiGAdp extends BaseAdapter {
    private Context context;
    private List<HistoryListBean.DataEntity> dataEntities = new ArrayList<>();

    public HistoryCaiGAdp(Context context, List<HistoryListBean.DataEntity> dataEntities) {
        this.context = context;
        this.dataEntities = dataEntities;
    }

    @Override
    public int getCount() {
        return dataEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return dataEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.history_caig_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        HistoryListBean.DataEntity dataEntity=dataEntities.get(position);
        switch (dataEntity.getType())
        {
            case "1"://面料
                viewHolder.tvHistoryName.setText("面料名称："+dataEntity.getName());
                viewHolder.tvHistorySizeTitle.setText("面料");
                viewHolder.tvHistorySize.setText(dataEntity.getNumber());
                viewHolder.tvHistoryComponentTitle.setText("成分");
                viewHolder.tvHistoryComponent.setText(dataEntity.getComponent_name());
                viewHolder.tvHistoryTime.setText("询价时间："+ TimeUtils.getMonth(Long.parseLong(dataEntity.getTimeline())));
                viewHolder.tvHistoryCity.setText(dataEntity.getCity());
                viewHolder.tvHistoryNum.setText("有"+dataEntity.getOffer()+"个报价");
                viewHolder.tvHistoryCityRight.setVisibility(View.GONE);
                viewHolder.tvHistoryCity.setVisibility(View.VISIBLE);
                viewHolder.tvHistoryNum.setVisibility(View.VISIBLE);
                break;
            case "2"://辅料
                viewHolder.tvHistoryName.setText("辅料名称："+dataEntity.getName());
                viewHolder.tvHistorySizeTitle.setText("数量");
                viewHolder.tvHistorySize.setText(dataEntity.getNumber());
                viewHolder.tvHistoryComponentTitle.setText("规格");
                viewHolder.tvHistoryComponent.setText(dataEntity.getSpecifications());
                viewHolder.tvHistoryTime.setText("询价时间："+ TimeUtils.getMonth(Long.parseLong(dataEntity.getTimeline())));
                viewHolder.tvHistoryCity.setText(dataEntity.getCity());
                viewHolder.tvHistoryNum.setText("有"+dataEntity.getOffer()+"个报价");
                viewHolder.tvHistoryCityRight.setVisibility(View.GONE);
                viewHolder.tvHistoryCity.setVisibility(View.VISIBLE);
                viewHolder.tvHistoryNum.setVisibility(View.VISIBLE);

                break;
            case "3"://货代
                viewHolder.tvHistoryName.setText("货运名称："+dataEntity.getName());
                viewHolder.tvHistorySizeTitle.setText("目的港");
                viewHolder.tvHistorySize.setText(dataEntity.getDestination_port());
                viewHolder.tvHistoryComponentTitle.setText("运输");
                viewHolder.tvHistoryComponent.setText(dataEntity.getTransport_mode());
                viewHolder.tvHistoryTime.setText("询价时间："+ TimeUtils.getMonth(Long.parseLong(dataEntity.getTimeline())));
                viewHolder.tvHistoryCity.setText(dataEntity.getCity());
                viewHolder.tvHistoryNum.setText("有"+dataEntity.getOffer()+"个报价");
                viewHolder.tvHistoryCityRight.setVisibility(View.GONE);
                viewHolder.tvHistoryCity.setVisibility(View.VISIBLE);
                viewHolder.tvHistoryNum.setVisibility(View.VISIBLE);

                break;
            case "4"://订单
                viewHolder.tvHistoryName.setText("订单数量："+dataEntity.getNum());
                viewHolder.tvHistorySizeTitle.setText("名称");
                viewHolder.tvHistorySize.setText(dataEntity.getStyle());
                viewHolder.tvHistoryComponentTitle.setText("面料");
                viewHolder.tvHistoryComponent.setText(dataEntity.getFabric_name());
                viewHolder.tvHistoryTime.setText("交货期："+ TimeUtils.getMonth(Long.parseLong(dataEntity.getHandle_time())));
//                viewHolder.tvHistoryCity.setText(dataEntity.getCity());
//                viewHolder.tvHistoryNum.setText("有"+dataEntity.getOffer()+"个报价");
                viewHolder.tvHistoryCityRight.setText(dataEntity.getCity());
                viewHolder.tvHistoryCityRight.setVisibility(View.VISIBLE);
                viewHolder.tvHistoryCity.setVisibility(View.INVISIBLE);
                viewHolder.tvHistoryNum.setVisibility(View.GONE);

                break;
        }
        return convertView;
    }



    class ViewHolder {
        @Bind(R.id.tv_history_name)
        TextView tvHistoryName;
        @Bind(R.id.tv_history_size_title)
        TextView tvHistorySizeTitle;
        @Bind(R.id.tv_history_size)
        TextView tvHistorySize;
        @Bind(R.id.tv_history_component_title)
        TextView tvHistoryComponentTitle;
        @Bind(R.id.tv_history_component)
        TextView tvHistoryComponent;
        @Bind(R.id.tv_history_time)
        TextView tvHistoryTime;
        @Bind(R.id.tv_history_city)
        TextView tvHistoryCity;
        @Bind(R.id.tv_history_num)
        TextView tvHistoryNum;
        @Bind(R.id.tv_history_city_right)
        TextView tvHistoryCityRight;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
